Periodic Tasks: emuperiodic

In order to create useful reports, it is necessary to populate the Statistics module with meaningful records. In the simplest case it is possible to create statistic records manually by collating system information and inserting new statistic records with the required keys, dates, times and value. However it would not take long before someone forget to add the required records thus rendering the analysis incomplete.

The Periodic Tasks facility provides a framework in which tasks can be executed on a regular basis. Each task is a perl script generating one or more records for insertion into the estatistics table. At the heart of the framework is the emuperiodic program.

The emuperiodic script is run at regular intervals to generate statistical information. Its primary purpose is to invoke all the task scripts for a given time period (hourly, daily, weekly, monthly). The usage message for emuperiodic is:

Usage: emuperiodic [-q] [-l] [-d yyyy:mm:dd[:HH:MM:SS]] period [script...]

where:

-d yyyy:mm:dd[:HH:MM:SS]

is the date to use for periodic tasks.

-l

only run local scripts (local/etc/periodic)

-q

specifies quiet mode, i.e. do not output progress.

period

specifies the time period for which statistical data is generated. Allowable values:

  • daily
  • hourly
  • monthly
  • weekly

    Extra periods may be added, e.g. fortnightly, as required.

If one or more scripts are provided on the command line, only the named script(s) in the periodic directory will be executed. The default is to run all scripts.

The Unix task scheduler cron is used to execute emuperiodic at the required intervals. The crontab entries used to invoke emuperiodic are:

#

# Run periodic tasks

#

30 * * * * /home/emu/client/bin/emurun emuperiodic hourly 2>&1 | /home/emu/client/bin/emurun emulogger -t "KE EMu Periodic Tasks Report" periodic

0 6 * * * /home/emu/client/bin/emurun emuperiodic daily 2>&1 | /home/emu/client/bin/emurun emulogger -t "KE EMu Periodic Tasks Report" periodic

30 6 * * 0 /home/emu/client/bin/emurun emuperiodic weekly 2>&1 | /home/emu/client/bin/emurun emulogger -t "KE EMu Periodic Tasks Report" periodic

0 7 1 * * /home/emu/client/bin/emurun emuperiodic monthly 2>&1 | /home/emu/client/bin/emurun emulogger -t "KE EMu Periodic Tasks Report" periodic

The table below shows when each instance of emuperiodic is executed:

Command

Executed

emuperiodic hourly 30 minutes past the hour being analysed.
emuperiodic daily 6 hours past the day being analysed.
emuperiodic weekly 6 hours and 30 minutes past the week being analysed, on the Sunday morning.
emuperiodic monthly 7 hours past the month being analysed.

All output from running periodic tasks is sent to emulogger which places the output into a file based on the current date (yyyy-mm-dd) in the logs/periodic directory. The log files provide a useful starting point if you suspect a problem with the execution of periodic tasks. As you can see, each task period is invoked after the time period for which it is generating statistics. The execution is delayed in order to allow any activities started in the task period to complete before the periodic tasks are run. It is also important to ensure that any system maintenance routines are not running while periodic tasks are executing, otherwise access to required tables may be denied.

When emuperiodic is invoked it looks for periodic tasks stored in either:

  • etc/periodic/period

    -OR-

  • local/etc/periodic/period

    where period is the argument supplied to emuperiodic (e.g. hourly). Each task is a perl script with a .pl (perl library) extension. If more than one task is found in the above directories, each task is executed sequentially in alphabetical order. Tasks in local/etc/periodic override scripts with the same name in etc/periodic.